package com.kaili.controller.web.v1;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.kaili.client.service.ISubEwbGenerator;
import com.kaili.common.stock.StockInfoBean;
import com.kaili.pojo.entity.HsEwbsDispatch;
import com.kaili.db.service.*;
import com.kaili.db.service.impl.HsOptRewbServiceImpl;
import com.kaili.common.exception.BaseExcept;
import com.kaili.except.PrintException;
import com.kaili.except.ResponseStatus;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Random;


@RestController
public class TestController {
    @Autowired
    IHsEwbsDispatchService dispatchService;
    @Autowired
    IHsBasicSeqService seqService;
    @Autowired
    IHsEwbsSignDetailService signDetailService;
    @Autowired
    IHsEwbsTransferService transferService;
    @Autowired
    HsOptRewbServiceImpl rewbService;
    @Autowired
    ISubEwbGenerator subEwbGenerator;
    @Autowired
    IHsEwbSubStockService subStockService;
    @RequestMapping("/hello")
    String test(){
        return "Hello World";
    }
    @RequestMapping("/exp")
    ResponseStatus exp() {
        return ResponseStatus.RESPONSE_TYPE_EMPTY;
    }
    @RequestMapping("/exp2")
    int exp2() throws BaseExcept {
        throw new PrintException(ResponseStatus.RESPONSE_TYPE_EMPTY);
    }

    @RequestMapping("/add")
    Object add() throws BaseExcept {
        StockInfoBean bean = new StockInfoBean();
        bean.setEwbNo("560560560");
        bean.setSiteId(13);
        bean.setSize(20);
        subStockService.ewbAddStock(bean);
        return "OK";
    }

    @RequestMapping("/modify1")
    Object modify1() throws BaseExcept {
        StockInfoBean bean = new StockInfoBean();
        bean.setEwbNo("564545455");
        bean.setSiteId(8888);
        bean.setSize(30);
        subStockService.ewbModifyStock(bean);
        return "OK";
    }

    @RequestMapping("/modify2")
    Object modify2() throws BaseExcept {
        StockInfoBean bean = new StockInfoBean();
        bean.setEwbNo("564545455");
        bean.setSiteId(8888);
        bean.setSize(5);
        subStockService.ewbModifyStock(bean);
        return "OK";
    }

    @RequestMapping("/send")
    Object send() throws BaseExcept {
        StockInfoBean bean = new StockInfoBean();
        bean.setEwbNo("560560560");
        bean.setSiteId(13);
        bean.setNextSiteId(14);
        bean.setSize(5);
        subStockService.sendEwbByBs(bean);
        return "OK";
    }

    @RequestMapping("/arrive")
    Object arrive() throws BaseExcept {
        StockInfoBean bean = new StockInfoBean();
        bean.setEwbNo("560560560");
        bean.setSiteId(14);
        bean.setPreSiteId(13);
        bean.setSize(5);
        subStockService.arriveEwbByBs(bean,true);
        return "OK";
    }

    @RequestMapping("/dispatch")
    Object dispatch() throws BaseExcept {
        StockInfoBean bean = new StockInfoBean();
        bean.setEwbNo("560560560");
        bean.setSiteId(14);
        bean.setSize(5);
        subStockService.dispatchEwbByBs(bean);
        return "OK";
    }

    @RequestMapping("/tttt")
    Object tttt(@ApiParam(value = "昵称", defaultValue = "234234234") @RequestParam String nickname) throws BaseExcept {
        StockInfoBean bean = new StockInfoBean();
        bean.setEwbNo("560560560");
        bean.setSiteId(14);
        bean.setSize(5);
        subStockService.dispatchEwbByBs(bean);
        return "OK";
    }

    @RequestMapping("/stowage")
    Object stowage() throws BaseExcept {
        StockInfoBean bean = new StockInfoBean();
        bean.setEwbNo("560560560");
        bean.setSiteId(13);
        bean.setSize(5);
        subStockService.stowageEwbByBs(bean);
        return "OK";
    }
    //@Cacheable("cache1")
    @RequestMapping("/cache")
    public Object cache1() throws BaseExcept {
        /*System.out.println("即时读取数据");
        Wrapper<HsEwbsDispatch> w = new EntityWrapper<HsEwbsDispatch>();
        w.where("rd_status",1);
        List<HsEwbsDispatch> infos =  dispatchService.selectList(w);
        HsEwbsDispatch dit = dispatchService.selectById(111);
        System.out.println(infos);
        System.out.println(dit);
        System.out.println(seqService.seqByType("QS"));
        System.out.println(seqService.seqByType("LD"));
        System.out.println(seqService.seqByType("PZ"));
        Map search = new HashMap();*/

        //return rewbService.getRewbList(new HashMap());
        return subEwbGenerator.getSubEwb("561101235", 200);
    }
    @Transactional
    @RequestMapping("/in")
    public int insert() throws BaseExcept {
        HsEwbsDispatch dispatch = new HsEwbsDispatch();
        dispatch.setOperationId(String.valueOf((long) new Random().nextInt(800)));
        dispatch.setCarId(1);
        dispatch.setDispatchNo("45654422");
        dispatchService.insert(dispatch);
        HsEwbsDispatch dispatch2 = new HsEwbsDispatch();
        dispatch2.setOperationId(String.valueOf((long) new Random().nextInt(800)));
        dispatch2.setCarId(1);
        dispatch2.setDispatchNo("5566");
        dispatchService.insert(dispatch2);

        Wrapper<HsEwbsDispatch> w = new EntityWrapper<HsEwbsDispatch>();
        w.where("rd_status",1);
        List<HsEwbsDispatch> infos =  dispatchService.selectList(w);
        System.out.println(infos);
        return 3;
    }
}